package com.pinyoumei.app.dialog;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.pinyoumei.app.R;

public class CallPhoneDialog extends Dialog implements View.OnClickListener{
    private Context context;
    private TextView ipd_phone,ipd_determine,ipd_cancel;
    private String phonenum;

    public CallPhoneDialog(Context context, int[] listenedItems, String phonenum){
        super(context, R.style.dialogStyle);//这个决定dialog的样式
        this.context = context;
        this.phonenum = phonenum;
    }
    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        Window window = getWindow();//获取一个窗口
        window.setGravity(Gravity.CENTER);//设置窗口的位置

        //window.setWindowAnimations(R.style.bottom_menu_animation);//设置窗口进入时的动画特效
        WindowManager.LayoutParams layoutParams = window.getAttributes();//获取窗口的属性赋值给layoutParams
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        window.setAttributes(layoutParams);//设置窗口的属性
        setCanceledOnTouchOutside(true);
        setContentView(R.layout.item_phone_dialog);
        ipd_phone = findViewById(R.id.ipd_phone);
        ipd_phone.setText("拨打"+phonenum);
        ipd_determine = findViewById(R.id.ipd_determine);
        ipd_determine.setOnClickListener(this);
        ipd_cancel = findViewById(R.id.ipd_cancel);
        ipd_cancel.setOnClickListener(this);
    }
    @Override
    public void onClick(View v){
        switch (v.getId()){
            case R.id.ipd_cancel:
                dismiss();
                break;
            case R.id.ipd_determine:
                Intent Intent = new Intent(android.content.Intent.ACTION_DIAL, Uri.parse("tel:" + phonenum));//跳转到拨号界面，同时传递电话号码
                context.startActivity(Intent);
                dismiss();
                break;
        }
    }
    @Override
    public void show(){
        super.show();
        /**
         * 设置宽度全屏，要设置在show的后面
         */
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.gravity = Gravity.CENTER;
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
        getWindow().getDecorView().setPadding(0, 0, 0, 0);
        getWindow().setAttributes(layoutParams);
    }
}